package com.lujianfei.tiananyungu.utils

import com.lujianfei.tiananyungu.HeadItem
import com.lujianfei.tiananyungu.shopmanager.Restaurant

object SortUtils {
    class HeadItemSort : Comparator<HeadItem> {
        override fun compare(o1: HeadItem?, o2: HeadItem?): Int {
            val num1 = StringUtils.getNumberFromString(o1?.title?:"")
            val num2 = StringUtils.getNumberFromString(o2?.title?:"")
            return StringUtils.compareVersion(num1, num2)
        }
    }

    /**
     * 排序优先级：正负 > 楼层数 > 区域
     */
    class SubItemSort : Comparator<Restaurant> {
        override fun compare(o1: Restaurant?, o2: Restaurant?): Int {

            val num1 = StringUtils.getNumberFromString(o1?.floor?:"").toIntOrNull()?:0
            val num2 = StringUtils.getNumberFromString(o2?.floor?:"").toIntOrNull()?:0

            val block1 = o1?.block?.hashCode()?:0
            val block2 = o2?.block?.hashCode()?:0

            val underground1  = o1?.floor?.contains("负") == true
            val underground2  = o2?.floor?.contains("负") == true

            if (underground1 && !underground2) {
                return -1
            } else if (!underground1 && underground2) {
                return 1
            }

            if (num1 > num2) {
                return 1
            } else if (num1 < num2) {
                return -1
            }

            return block1 - block2
        }
    }
}